<?php
/**
 * file: TrackController.class.php
 *
 * todo...
 * @author 
 * @copyright Copyright (C)  All rights reserved.
 * @version $Id: TrackController.class.php 1.0 2014-12-17 14:05:27Z $
 * @package Controller
 * @since 1.0
 */

class TrackController extends Controller {

	function __construct() {

	}

	public function indexAction() {
		echo "index";
	}
	public function FedexAction(){
		
		$this->import(APP_ROOT."/tracker/fedex.php");
		$p1 = new kdtrace_fedex(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function TntAction(){
		
		$this->import(APP_ROOT."/tracker/tnt.php");
		$p1 = new kdtrace_tnt(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function DhlAction(){
		
		$this->import(APP_ROOT."/tracker/dhl.php");
		$p1 = new kdtrace_dhl(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function UpsAction(){
		
		$this->import(APP_ROOT."/tracker/ups.php");
		$p1 = new kdtrace_ups(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function TollAction(){
		
		$this->import(APP_ROOT."/tracker/toll.php");
		$p1 = new kdtrace_toll(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function NiceAction(){
		
		$this->import(APP_ROOT."/tracker/nice.php");
		$p1 = new kdtrace_nice(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function MasterAction(){
		
		$this->import(APP_ROOT."/tracker/master.php");
		$p1 = new kdtrace_master(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function DnjExAction(){
		
		$this->import(APP_ROOT."/tracker/dnjex.php");
		$p1 = new kdtrace_dnjex(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function JzexAction(){
		
		$this->import(APP_ROOT."/tracker/jzex.php");
		$p1 = new kdtrace_jzex(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function AramexAction(){
		
		$this->import(APP_ROOT."/tracker/aramex.php");
		$p1 = new kdtrace_aramex(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function JiachengExAction(){
		
		$this->import(APP_ROOT."/tracker/jiachengex.php");
		$p1 = new kdtrace_jiachengex(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function RpxExAction(){
		
		$this->import(APP_ROOT."/tracker/rpxex.php");
		$p1 = new kdtrace_rpxex(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function UrgentAction(){
		
		$this->import(APP_ROOT."/tracker/urgent.php");
		$p1 = new kdtrace_urgent(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	public function XiaobaoAction(){
		
		$this->import(APP_ROOT."/tracker/xiaobao.php");
		$p1 = new kdtrace_xiaobao(); 
		$tckrec = $p1->track($this->get("tracknum") , $this->get("lang"));
		$result = $this->clTrackRec($tckrec);
		echo $result;
	}
	
	function clTrackRec( $arr ) { 
		if(!is_array($arr) || !isset($arr)){
			return "11";
		};
		$datatype = strtolower($this->get("type"));
		if($datatype == ""){
			$datatype = "json";
		}
		if($datatype != "xml"){
			$arr['header'] = (object) $arr['header'];
		}

		if($datatype == "json"){
			$result = json_encode($arr);
		}
		if($datatype == "array"){
			 print_r($arr);
			exit;
		}
		if($datatype == "xml"){
			$this->import("array2xml");
			$schs = new array2xml();
			$schs->put($arr);
			$result = $schs->getXml();
		}
		if($datatype == "jsonp"){
			$result = $this->get("callback") . "(" . json_encode($arr) . ")";
		}
		
		if($result==""){
			$result = "无数据（no_data）";
		}
		
		return $result;
	}
}